import type {ToastType} from "tailvue/src/types/toast";
import type {PushButtonThemeName} from "tailvue/src/types/push-button";
import type {ModalType} from "tailvue/src/types/modal";
import {inBrowser} from "~/utils/nuxt/constants";

let useToast: any
let useModal: any

if (inBrowser) {
    import('tailvue').then((res) => {
        useToast = res.useToast
        useModal = res.useModal
    })
}

export interface ModalOptions {
    type: ModalType;
    title: string;
    body: string;
    primary: {
        label: string;
        theme: PushButtonThemeName;
        action: () => void;
    };
    secondary: {
        label: string;
        theme: PushButtonThemeName;
        action: () => void;
    };
}

export const showMessage = (message: string, type: ToastType = "success", timeout: number = 1) => {
    useToast().show({
        type: type,
        message: message,
        timeout: timeout,
    })

}
export const showModal = (options: ModalOptions) => {
    useModal().show({
        type: options.type,
        title: options.title,
        body: options.body,
        primary: {
            label: options.primary.label,
            theme: options.primary.theme,
            action: options.primary.action,
        },
        secondary: {
            label: options.secondary.label,
            theme: options.secondary.theme,
            action: options.secondary.action,
        },
    });
}
